package oldCodePackage;
import java.io.*;

public class Human extends Player{
	private static int numPlayers;
	private BufferedReader input = new BufferedReader (new InputStreamReader(System.in)); 

	Human(){
		this.myName = "Player " + numPlayers;
		numPlayers++;
	}
	Human(String name){
		this.myName = name;
		numPlayers++;
	}

	@Override
	public int placeBid() throws IOException {
		String inStr;
		int bidSel = -1;
		int suitSel = -1;
		int numBid = -1;
		boolean valid = false;
		System.out.println("~~~~~~~~~~~~~~~~~");
		System.out.println(myName + "'s turn, please press enter to continue: ");
		inStr = input.readLine();
		
		do{
			valid = true;
			
			printSelMenu();
			inStr = input.readLine();
			bidSel = Integer.parseInt(inStr); 
			
			if(highestBid == -1 && (bidSel == 2 || bidSel == 3)){//pass or call on first bid
				System.out.println("*~Invalid, no current Bid~*");
				valid = false;
			}
			else if(highestBid == -1 && bidSel == 1){//nil on first bid
				do{
					printSuitSel();
					inStr = input.readLine();
					suitSel = Integer.parseInt(inStr);
				}while(suitSel < 0 || suitSel > 5);
				
				trumpSuit = suitSel;
				highestBid = 0;
				highestBidder = myName;
				tricksBid = 0;
			}
			else if(bidSel == 1)//nil
				tricksBid = 0;
			else if(bidSel == 2)//pass
				tricksBid = -1;
			else if(bidSel == 3)//call
				tricksBid = highestBid;
			else if(bidSel == 4){//raise
				do{
					System.out.println("~~~~~~~~~~~~~~~~~");
					System.out.println("Please enter how many you wish to take: ");
					inStr = input.readLine();
					numBid = Integer.parseInt(inStr);
				}while(numBid < 0);
				do{
					printSuitSel();
					inStr = input.readLine();
					suitSel = Integer.parseInt(inStr);
				}while(suitSel < 0 || suitSel > 5);
				
				trumpSuit = suitSel;
				highestBid = numBid;
				highestBidder = myName;
				tricksBid = numBid;
			}
			else{
				System.out.println("*~Invalid Number Selection~*");
				valid = false;
			}
		}while(!valid);

		return tricksBid;
	}
	
	private void printSelMenu() {
		System.out.println("*****************");
		printMyHand();
		System.out.println("~~~~~~~~~~~~~~~~~");
		printHighestBider();
		System.out.println("~~~~~~~~~~~~~~~~~");
		System.out.println("1. Nil");
		System.out.println("2. Pass");
		System.out.println("3. Call");
		System.out.println("4. Raise");
		System.out.println("Please select from between 1-4: ");
	}

	private void printMyHand() {
		System.out.println("My Cards: ");
		for(Card card : myHand)
			System.out.println(card.printCard());
	}

	private void printSuitSel(){
		System.out.println("~~~~~~~~~~~~~~~~~");
		System.out.println("0. All Trump");
		System.out.println("1. Clubs");
		System.out.println("2. Diamonds");
		System.out.println("3. Hearts");
		System.out.println("4. Spades");
		System.out.println("5. No Trump");
		System.out.println("Please enter a suit: ");
	}
	
	private void printHighestBider(){
		String bid = "The Current Bid is ";
		
		if(highestBid == -1)
			bid += "nothing";
		else if(highestBid == 0)
			bid += "nil";
		else
			bid += highestBid;
		bid += " " + trumpSuit + " by " + highestBidder;
		
		System.out.println(bid);
	}

	@Override
	public Card playCard() {
		System.out.println("playCard!");
		return Game.ACE_OF_HEARTS;
	}
}
